﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using JMT.Data;

namespace JMT.Controls
{
    /// <summary>
    /// JDiagramContainer.xaml 的交互逻辑
    /// </summary>
    public partial class JDiagramContainer : UserControl
    {
        public JDiagramContainer()
        {
            InitializeComponent();

            //TabItem newTabItem = new TabItem();
            //Button newTabButton = new Button();
            //newTabButton.Content = "+";
            //newTabButton.Width = 50;
            //newTabButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            //newTabButton.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            ////newTabButton.Click += new RoutedEventHandler(newTabButton_Click);
            //newTabItem.Header = newTabButton;
            //newTabItem.Padding = new Thickness(0);
            //newTabItem.Margin = new Thickness(0);
            //newTabItem.BorderThickness = new Thickness(0);
            //_ctlTabContainer.Items.Add(newTabItem);
        }

        public void Show(JSolution jSolution, JDiagram jDiagram)
        {
            foreach (TabItem item in _ctlTabContainer.Items)
            {
                if (item.Tag != null && (item.Tag as JDiagram).Id == jDiagram.Id)
                {
                    item.IsSelected = true;
                    return;
                }
            }

            TextBlock headerText = new TextBlock();
            headerText.SetBinding(TextBlock.TextProperty, "Name");
            headerText.DataContext = jDiagram;

            ClassDiagram diagram = new Controls.ClassDiagram(jSolution, jDiagram);
            TabItem tabItem = new TabItem();
            tabItem.Header = headerText;
            tabItem.Content = diagram;
            tabItem.Tag = jDiagram;
            _ctlTabContainer.Items.Add(tabItem);
            tabItem.IsSelected = true;
        }

        public void Clear()
        {
            _ctlTabContainer.Items.Clear();
        }

        public ClassDiagram GetCurrent()
        {
            return this._ctlTabContainer.SelectedContent as ClassDiagram;
        }
    }
}
